package com.rongjih.learn.webflux;

import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.SynchronousSink;

import java.time.Duration;

@Service
public class StudentService {

  public Flux<Student> all() {
    return Flux.generate((SynchronousSink<Student> sink) -> sink.next(new Student(next())))
      .delayElements(Duration.ofSeconds(1L));
  }

  private int count = 0;

  private String next() {
    return Thread.currentThread().getId() + "-" + (++count);
  }
}
